package cn.liye.pingfen.controller;

import cn.liye.pingfen.pojo.dto.UserLoginDTO;
import cn.liye.pingfen.pojo.dto.UserRegDTO;
import cn.liye.pingfen.pojo.dto.UserUpdateDTO;
import cn.liye.pingfen.pojo.vo.UserVO;
import cn.liye.pingfen.response.JsonResult;
import cn.liye.pingfen.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "用户模块")
@RestController
@Validated
@RequestMapping("/v1/users")
public class UserController {

    @Autowired
    IUserService service;


    @ApiOperation("注册功能")
    @PostMapping("/reg")
    @Validated
    public JsonResult reg(@Validated UserRegDTO userRegDTO) {
        service.reg(userRegDTO);
        return JsonResult.ok();
    }

    @ApiOperation("登录功能")
    @PostMapping("/login")
    public JsonResult login(UserLoginDTO userLoginDTO) {
        UserVO userVO = service.login(userLoginDTO);
        return JsonResult.ok(userVO);
    }

    @ApiOperation("验证码登录功能")
    @PostMapping("/loginsms")
    public JsonResult loginsms(UserLoginDTO userLoginDTO) {
        UserVO userVO = service.loginsms(userLoginDTO);
        System.out.println("userVO=" + userVO);
        return JsonResult.ok(userVO);
    }


    @ApiOperation("修改密码")
    @PostMapping("/update")
    public JsonResult update(UserUpdateDTO userUpdateDTO){
        service.update(userUpdateDTO);
        return JsonResult.ok();
    }


    @ApiOperation("获取验证码功能")
    @PostMapping("/sms")
    public JsonResult sms(UserRegDTO userRegDTO) {
        UserRegDTO sms = service.sms(userRegDTO);
        return JsonResult.ok(sms);
    }

}